const jwtHelper = require("./token");
// 验证token中间件
const authMiddleware = {
  verifyToken: (req, res, next) => {
    const token = req.headers["authorization"];
    if (!token) {
      return res.status(401).send("访问被拒绝，没有提供token");
    }

    const decoded = jwtHelper.verifyToken(token);
    if (!decoded) {
      return res.status(401).send("无效的token");
    }

    req.user = decoded;
    next();
  },
};
module.exports = authMiddleware;